package my1024.view;

import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import my1024.app.Const;
import my1024.model.Line;

public class GridLine {
	private TransformGroup root;

	public GridLine() {
		root = new TransformGroup();
		root.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		root.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

		Vector3f vTrans = new Vector3f(-Const.BOX_BOUND * 2.0f,
				-Const.BOX_BOUND * 2.0f, 0.0f);
		Transform3D translation = new Transform3D();
		translation.setTranslation(vTrans);
		root.setTransform(translation);
	}

	public void createGridLine() {
		float y1 = 0;
		float y2 = y1 + Const.MAX_ROW * Const.BOX_BOUND;
		for (int col = 0; col <= Const.MAX_COL; ++col) {
			float x = col * Const.BOX_BOUND;

			Line myLine1 = new Line(new Point3f(x, y1, 0.0f), new Point3f(x, y2, 0.0f));
			root.addChild(myLine1.getShape());
		}

		float x1 = 0;
		float x2 = x1 + Const.MAX_COL * Const.BOX_BOUND;
		for (int row = 0; row <= Const.MAX_ROW; ++row) {
			float y = row * Const.BOX_BOUND;

			Line myLine2 = new Line(new Point3f(x1, y, 0.0f), new Point3f(x2, y, 0.0f));
			root.addChild(myLine2.getShape());
		}
	}

	public TransformGroup getGridLine() {
		return root;
	}
}
